package com.andy.note.main.model.proxy.demo4;

import java.lang.reflect.Proxy;

/**
 * 
 * JDK 动态代理
 * 参考文章：
 * https://mp.weixin.qq.com/s?__biz=MzUyODg4Nzk2MQ==&mid=2247497877&idx=6&sn=93a5b4d3a175ceef36933b523605391a&chksm=fa6bc163cd1c487571ea1fec2d43d8e608ead38a6bfd574b7280e8acc5d6b37e87f62c1143fa&mpshare=1&scene=1&srcid=&sharer_sharetime=1593436371336&sharer_shareid=312fad5cd41c60dcb1603d5533e7f95d&key=252c2f02cf26eb6b8efbe08c7916b8d1914223a9ed9f20a582c954950c48ec596153df36a4776b6871d2171cb69f9ef2a2f3d9f171279a1e525163c82cf63c19e03175b34da62f0a61fa015823d279e9&ascene=1&uin=NzI1MTE4MzAw&devicetype=Windows+10+x64&version=62090070&lang=zh_CN&exportkey=AZNHwDBp1ZaurhDpzIFCgvA%3D&pass_ticket=wGMAUpWRjPkkH52YVka8rx3iirVFMPEYvMgzJS1kyu2aK074MqwhB%2FDIhbP3asZv
 * 
 * @author Andy
 * @version $Revision: 1.1 $ $Date: 2020年6月30日 上午11:43:36 $
 */
public class Test {

    public static void main(String[] args) {
        Myself myself = new Myself();
        // 创建代理对象，这里有三个参数，第一个是类的ClassLoader，第二个是该类的接口集合，第三个就是InvocationHandler
        Object o = Proxy.newProxyInstance(myself.getClass().getClassLoader(), myself.getClass().getInterfaces(),
                new InvocationHandlerImpl(myself));
        Person person = (Person) o;
        person.buyCar();
    }
}